﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Tools.Model
{
    public static class MemberInfoExtensions
    {
        public static T GetAttribute<T>(this MemberInfo memberInfo)
            where T : Attribute
        {
            return GetAttribute<T>(memberInfo, true);
        }

        public static T GetAttribute<T>(this MemberInfo memberInfo, bool inherit)
            where T : Attribute
        {
            return (T)Attribute.GetCustomAttribute(memberInfo, typeof(T), inherit);

        }

        public static Boolean HasAttribute<T>(this MemberInfo memberInfo)
            where T : Attribute
        {
            return HasAttribute<T>(memberInfo, true);

        }

        public static Boolean HasAttribute<T>(this MemberInfo memberInfo, bool inherit)
            where T : Attribute
        {
            return Attribute.GetCustomAttribute(memberInfo, typeof(T), inherit) != null;
        }

        public static T[] GetAttributes<T>(this MemberInfo memberInfo)
            where T : Attribute
        {
            return GetAttributes<T>(memberInfo, true);
        }
        public static T[] GetAttributes<T>(this MemberInfo memberInfo, bool inherit)
            where T : Attribute
        {
            return (T[])Attribute.GetCustomAttributes(memberInfo, typeof(T), inherit);
        }

    }
}
